<template>
  <el-form :model="ruleForm" ref="ruleForm" :class="isEdit?'':'formItem'"
           :label-position="labelPosition">
    <el-card class="box-card" shadow="never">
      <div slot="header" class="header-card">
        <span class="header-card-title">处置结果</span>
      </div>

      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="处置时间:" prop="disposalScrapTime"
                        :rules="!isEdit? [] : rules.disposalScrapTime ">
            <el-date-picker v-model="ruleForm.disposalScrapTime" type="date" placeholder="请选择处置时间"
                            v-if="isEdit"
                            value-format='yyyy-MM-dd' style="width: 100%;" />
            <span v-else>{{ ruleForm.disposalScrapTime }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="原因:" prop="disposalScrapDetails">
            <el-input v-if="isEdit" type="textarea" v-model="ruleForm.disposalScrapDetails" placeholder="请输入处置原因"
                      :rows="4" maxlength="500" show-word-limit/>
            <div v-else>{{ ruleForm.disposalScrapDetails || '-'}}</div>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="附件:" prop="disposalScrapAttachment"
                        :rules="!isEdit? [] : rules.disposalScrapAttachment ">
            <image-common v-model="ruleForm.disposalScrapAttachment" :limit="20" :disabled="!isEdit" :upType="2"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-card>
  </el-form>
</template>

<script>
export default {
  name: 'disposalResult',//处置结果
  props: {
    value: {
      type: Object,
      default: () => {
        return {};
      },
    },
    state: {
      type: String,
      default: "",
    },
  },

  computed: {
    ruleForm: {
      get() {
        let that = this
        const proxy = new Proxy(that.value, {
          get(target, key, value) {
            return Reflect.get(target, key)
          }
        })
        return proxy
      }
    },
    isEdit() {
      let bool;
      switch (this.state) {
        case "write":
          bool = true;
          break;
        case "disabled":
          bool = false;
          break;
        case "readonly":
          bool = false;
          break;
      }
      return bool
    },
    labelPosition() {
      if (this.state === 'write') {
        return 'top'
      } else {
        return 'right'
      }
    },
  },
  watch: {},
  data() {
    return {
      rules: {
        disposalScrapTime: [
          {required: true, message: '请选择处置时间', trigger: 'blur'}
        ],
        disposalScrapAttachment: [
          {required: true, message: '请上传附件', trigger: 'blur'}
        ]
      }
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    valid() {
      return new Promise((resolve) => {
        this.$refs.ruleForm.validate((valid) => {
          resolve(valid);
        });
      });
    },

    handleEffect() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate((valid) => {
          if (valid) {
            resolve()
          } else {
            reject()
          }
        });
      });
    }
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/cwgd/formScss.scss";

</style>


